package com.yan.club.result;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * @author : 彦
 * @since : 2023/11/14 14:37
 */
@Schema(description = "通用返回")
@Data
public class Result<T> {

    /**
     * 编码
     */
    @Schema(description = "编码")
    private int code;

    /**
     * 消息
     */
    @Schema(description = "消息")
    private String msg;

    /**
     * 数据
     */
    @Schema(description = "数据")
    private T data;

    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.code = 200;
        result.msg = "操作成功";
        return result;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = success();
        result.data = data;
        return result;
    }

    public static <T> Result<T> error(int code, String msg) {
        Result<T> result = new Result<>();
        result.code = code;
        result.msg = msg;
        return result;
    }

    public static <T> Result<T> error(int code, String msg, T data) {
        Result<T> result = new Result<>();
        result.code = code;
        result.msg = msg;
        result.data = data;
        return result;
    }
}
